package Service;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
@WebServlet("/responseDemo1")
public class ResponseServlet1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /*重写方法
        * 路径：
        * 虚拟路径 /respondemo2 资源路径/responseDemo2
        * 完整路径：虚拟路径+资源路径/responsedemo2 /response2
        * +*/
        /*动态获取虚拟目录*/
        String contextPath=req.getContextPath();
        System.out.println(contextPath);//      /Project
        resp.sendRedirect(contextPath+"/response2");
        resp.sendRedirect("https://www.baidu.com");
        /*请求转发只有资源路径*/
//        req.getRequestDispatcher("/responsdemo2").forward(req,resp);
    }
}
